# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: db\tables\locations.py
__author__ = "sanyi"
from sqlalchemy import *
from sqlalchemy.orm import mapper
from sqlalchemy.dialects.postgresql import UUID as C_UUID
from sqlalchemy.dialects.postgresql import ARRAY as C_ARRAY
from sqlalchemy.types import TypeDecorator
from db.tables import metadata

loc_type_str_to_int = dict(file=0, folder=1, ip=2, port=3)
loc_type_int_to_str = dict(
    zip(loc_type_str_to_int.values(), loc_type_str_to_int.keys())
)


class LocationType(TypeDecorator):
    impl = INTEGER

    def process_bind_param(self, value, dialect):
        return loc_type_str_to_int.get(value)

    def process_result_value(self, value, dialect):
        return loc_type_int_to_str.get(value)

    def python_type(self):
        return str

    def process_literal_param(self, value, dialect):
        pass


LocationsTable = Table(
    "locations",
    metadata,
    Column("loc_id", INTEGER, nullable=False, primary_key=True),
    Column(
        "scan_session_id",
        C_UUID,
        ForeignKey("scan_sessions.scan_session_id", ondelete="CASCADE"),
        nullable=False,
        primary_key=True,
        index=True,
    ),
    Column("name", TEXT, nullable=False),
    Column("parent_id", INTEGER, index=True),
    Column("source_id", INTEGER, index=True),
    Column("root_id", INTEGER, index=True),
    Column("tags", C_ARRAY(TEXT), index=True),
    Column("path", TEXT),
    Column("loc_type", LocationType),
    Column("input_data", TEXT),
    ForeignKeyConstraint(
        ["scan_session_id", "parent_id"],
        ["locations.scan_session_id", "locations.loc_id"],
        ondelete="CASCADE",
    ),
)


class LocationRow(object):
    loc_id = None
    parent_id = None
    scan_session_id = None
    tags = None
    root_id = None
    path = None
    loc_type = None
    name = None
    source_id = None
    input_data = None

    def __str__(self):
        return "R_location:%s:%s" % (self.scan_session_id, self.loc_id)

    def __repr__(self):
        return self.__str__()


mapper(LocationRow, LocationsTable)
